const Controller = require('egg').Controller;

class UserController extends Controller {
    async login() {
        const {ctx,app} = this;
        const data = await ctx.service.user.login()
        if(data.token) {
            ctx.body = {
                code:1,
                data
            };
        } else {
            ctx.body  = {
                code:-1,
                message:"请检查账号密码"
            }
        }
    }
    async register() {
        const {ctx,app} = this;
        const data = await ctx.service.user.register()
        if(data.affectedRows ===1) {
            ctx.body = {
                code:1,
                message:"注册成功"
            };
        } else {
            ctx.body  = {
                code:-1,
                message:"注册失败"
            }
        }
    }
}

module.exports = UserController;
